<template>
  <div id="app">
    <!-- 顶部导航栏 -->
    <header class="app-header">
      <div class="logo">Qiankun 微前端示例</div>
      <nav class="nav">
        <router-link to="/" class="nav-item">首页</router-link>
        <router-link to="/user" class="nav-item">用户管理</router-link>
        <router-link to="/order" class="nav-item">订单管理</router-link>
      </nav>
      <div class="actions">
        <button @click="changeTheme">切换主题</button>
      </div>
    </header>
    
    <!-- 主内容区 -->
    <main class="app-main">
      <router-view />
    </main>
    
    <!-- 页脚 -->
    <footer class="app-footer">
      基于 qiankun 的微前端示例 © 2023
    </footer>
  </div>
</template>

<script setup>
// 切换全局主题
const changeTheme = () => {
  const currentTheme = document.documentElement.getAttribute('data-theme') || 'light'
  const newTheme = currentTheme === 'light' ? 'dark' : 'light'
  
  document.documentElement.setAttribute('data-theme', newTheme)
  
  // 更新全局状态
  window.setMainAppState({
    theme: newTheme
  })
}
</script>

<style>
/* 全局样式 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  color: #333;
  background-color: #f5f7fa;
}

/* 头部样式 */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 60px;
  background-color: #165DFF;
  color: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.logo {
  font-size: 18px;
  font-weight: bold;
}

.nav {
  display: flex;
  gap: 20px;
}

.nav-item {
  color: white;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 4px;
  transition: background-color 0.3s;
}

.nav-item:hover,
.nav-item.router-link-exact-active {
  background-color: rgba(255, 255, 255, 0.2);
}

.actions button {
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  background-color: rgba(255, 255, 255, 0.2);
  color: white;
  cursor: pointer;
  transition: background-color 0.3s;
}

.actions button:hover {
  background-color: rgba(255, 255, 255, 0.3);
}

/* 主内容区 */
.app-main {
  max-width: 1200px;
  margin: 20px auto;
  padding: 0 20px;
}

/* 页脚 */
.app-footer {
  text-align: center;
  padding: 20px;
  color: #666;
  border-top: 1px solid #eee;
  margin-top: 40px;
}

/* 深色主题 */
[data-theme="dark"] {
  --bg-color: #1f1f1f;
  --text-color: #f5f5f5;
}

[data-theme="dark"] body {
  background-color: var(--bg-color);
  color: var(--text-color);
}

[data-theme="dark"] .app-main {
  background-color: #2c2c2c;
}
</style>
